﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ImageScaleControl : MonoBehaviour
{
    float percent;
    public float speed;
    public enum scaleType
    {
        horizontal,vertical,mix
    }

    public scaleType mscaleType;
    Vector3 originalVec, endVec;

    bool isNotFirst;
    Vector3 recordVec;
    // Use this for initialization
    void Awake()
    {
        recordVec = transform.localScale;
    }

    // Update is called once per frame
    void Update()
    {
        if(percent!=1)
        {
            percent += Time.deltaTime * speed;
            percent = Mathf.Min(1, percent);
            transform.localScale = Vector3.Lerp(originalVec, endVec, percent);
        }
    }
    void OnEnable()
    {
      
       Initialized();
        
    }

    private void OnDisable()
    {
        transform.localScale = recordVec;
    }

    void Initialized()
    {
        switch (mscaleType)
        {
            case scaleType.horizontal:
                {
                    originalVec = new Vector3(0, transform.localScale.y, transform.localScale.z);
                    endVec = transform.localScale;
                    transform.localScale = originalVec;
                }
                break;
            case scaleType.vertical:
                {
                    originalVec = new Vector3(transform.localScale.x, 0, transform.localScale.z);
                    endVec = transform.localScale;
                    transform.localScale = originalVec;
                }
                break;
            case scaleType.mix:
                {
                    originalVec = new Vector3(0, 0, transform.localScale.z);
                    endVec = transform.localScale;
                    transform.localScale = originalVec;
                }
                break;
        }
        percent = 0;
    }
}
